Coverage Report

Created: 2024-12-26 12:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
D:\a\tools.proto\tools.proto\compiler\src\api\tools\rust.rs
Line
Count
Source
1
// Copyright (c) 2024, BlockProject 3D
2
//
3
// All rights reserved.
4
//
5
// Redistribution and use in source and binary forms, with or without modification,
6
// are permitted provided that the following conditions are met:
7
//
8
//     * Redistributions of source code must retain the above copyright notice,
9
//       this list of conditions and the following disclaimer.
10
//     * Redistributions in binary form must reproduce the above copyright notice,
11
//       this list of conditions and the following disclaimer in the documentation
12
//       and/or other materials provided with the distribution.
13
//     * Neither the name of BlockProject 3D nor the names of its contributors
14
//       may be used to endorse or promote products derived from this software
15
//       without specific prior written permission.
16
//
17
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29
use crate::api::config;
30
use crate::api::config::model;
31
use crate::api::config::model::Config;
32
use crate::api::core::generator::{Context, Generator};
33
use crate::api::tools::Error;
34
use crate::api::tools::GenTools;
35
use crate::gen::{GeneratorRust, RustImportSolver, RustParams};
36
37
pub struct Rust;
38
39
impl GenTools for Rust {
40
    type Params<'a> = model::RustParams<'a>;
41
    type Generator = GeneratorRust;
42
    type Solver = RustImportSolver;
43
44
3
    fn new_solver() -> Self::Solver {
45
3
        RustImportSolver
46
3
    }
47
48
3
    fn new_generator() -> Self::Generator {
49
3
        GeneratorRust
50
3
    }
51
52
3
    fn generate<'b>(
53
3
        generator: &'b Generator<'_, Self::Generator>,
54
3
        context: &mut Context<'b, Self::Solver>,
55
3
        config: &Config<Self::Params<'_>>,
56
3
    ) -> Result<(), Error> {
57
3
        config::core::generate(
58
3
            generator,
59
3
            context,
60
3
            config,
61
12
            |v| {
62
12
                if v.disable_write.is_none()
  Branch (62:20): [True: 12, False: 0]
  Branch (62:20): [Folded - Ignored]
63
12
                    && v.disable_read.is_none()
  Branch (63:24): [True: 12, False: 0]
  Branch (63:24): [Folded - Ignored]
64
12
                    && v.write_async.is_none()
  Branch (64:24): [True: 7, False: 5]
  Branch (64:24): [Folded - Ignored]
65
7
                    && v.union_set_discriminant.is_none()
  Branch (65:24): [True: 6, False: 1]
  Branch (65:24): [Folded - Ignored]
66
6
                    && v.list_wrappers.is_none()
  Branch (66:24): [True: 3, False: 3]
  Branch (66:24): [Folded - Ignored]
67
3
                    && v.struct_to_mut.is_none()
  Branch (67:24): [True: 3, False: 0]
  Branch (67:24): [Folded - Ignored]
68
3
                    && v.struct_dupe.is_none()
  Branch (68:24): [True: 2, False: 1]
  Branch (68:24): [Folded - Ignored]
69
2
                    && v.message_offsets.is_none()
  Branch (69:24): [True: 1, False: 1]
  Branch (69:24): [Folded - Ignored]
70
                {
71
1
                    return None;
72
11
                }
73
11
                let mut params = RustParams::default();
74
11
                if let Some(
v0
) = &v.disable_read {
  Branch (74:24): [True: 0, False: 11]
  Branch (74:24): [Folded - Ignored]
75
0
                    for v in v {
76
0
                        params = params.disable_read(v);
77
0
                    }
78
11
                }
79
11
                if let Some(
v0
) = &v.disable_write {
  Branch (79:24): [True: 0, False: 11]
  Branch (79:24): [Folded - Ignored]
80
0
                    for v in v {
81
0
                        params = params.disable_write(v);
82
0
                    }
83
11
                }
84
11
                if let Some(
v1
) = &v.struct_dupe {
  Branch (84:24): [True: 1, False: 10]
  Branch (84:24): [Folded - Ignored]
85
2
                    for 
v1
in v {
86
1
                        params = params.enable_struct_dupe(v);
87
1
                    }
88
10
                }
89
11
                params = params.enable_write_async(v.write_async.unwrap_or_default());
90
11
                params = params.enable_union_set_discriminant(v.union_set_discriminant.unwrap_or_default());
91
11
                params = params.enable_list_wrappers(v.list_wrappers.unwrap_or_default());
92
11
                params = params.enable_struct_to_mut(v.struct_to_mut.unwrap_or_default());
93
11
                params = params.enable_message_offsets(v.message_offsets.unwrap_or_default());
94
11
                Some(params)
95
12
            },
96
3
            &RustParams::default(),
97
3
        )
?0
;
98
3
        Ok(())
99
3
    }
100
}